{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6e8ce2ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "def greet_user():\n",
    "    \"\"\"问候语函数\"\"\"\n",
    "    print(\"hello world!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5fc89f71",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "greet_user()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7d9eb293",
   "metadata": {},
   "outputs": [],
   "source": [
    "def greet_user(username):\n",
    "    \"\"\"问候语函数\"\"\"\n",
    "    print(\"hello\",username)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a568e970",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "greet_user(\"world\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "86748b80",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 函数实践\n",
    "def NFU_NEWS_URL(分类,页码):\n",
    "    \"\"\"可以快速查询广州南方学院新闻的页面链接\"\"\"\n",
    "    for i in range(页码):\n",
    "        print(\"https://wwww.nfu.edu.cn/\"+分类+\"/index\"+str(i)+\".htm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "113a87cc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function NFU_NEWS_URL in module __main__:\n",
      "\n",
      "NFU_NEWS_URL(分类, 页码)\n",
      "    可以快速查询广州南方学院新闻的页面链接\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(NFU_NEWS_URL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "961dd04b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://wwww.nfu.edu.cn/xxyw/index0.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index1.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index2.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index3.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index4.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index5.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index6.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index7.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index8.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index9.htm\n"
     ]
    }
   ],
   "source": [
    "NFU_NEWS_URL(\"xxyw\",10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "363ef172",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://wwww.nfu.edu.cn/tzgg/index0.htm\n",
      "https://wwww.nfu.edu.cn/tzgg/index1.htm\n",
      "https://wwww.nfu.edu.cn/tzgg/index2.htm\n",
      "https://wwww.nfu.edu.cn/tzgg/index3.htm\n",
      "https://wwww.nfu.edu.cn/tzgg/index4.htm\n"
     ]
    }
   ],
   "source": [
    "NFU_NEWS_URL(\"tzgg\",5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3cf09da4",
   "metadata": {},
   "source": [
    "## 模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9bb635d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import nfu_crawl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "37f6ba70",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://wwww.nfu.edu.cn/xxyw/index0.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index1.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index2.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index3.htm\n",
      "https://wwww.nfu.edu.cn/xxyw/index4.htm\n"
     ]
    }
   ],
   "source": [
    "nfu_crawl.NFU_NEWS_URL(\"xxyw\",5)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25cb2f69",
   "metadata": {},
   "source": [
    "## 关于实参和形参"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62eee744",
   "metadata": {},
   "outputs": [],
   "source": [
    "* positional argument(位置参数)\n",
    "* keyword argument(关键字参数)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "40d7ec20",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func_test(x,y):\n",
    "    print(x)\n",
    "    print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "4398f12e",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "positional argument follows keyword argument (278723003.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [26]\u001b[1;36m\u001b[0m\n\u001b[1;33m    func_test(x=1,2)\u001b[0m\n\u001b[1;37m                   ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m positional argument follows keyword argument\n"
     ]
    }
   ],
   "source": [
    "func_test(x=1,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "95515fdd",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func_test(x,y):\n",
    "    print(x)\n",
    "    print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "36c8a66a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "func_test(1,y=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "8be52071",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func_test(x,y):\n",
    "    print(x)\n",
    "    print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "e5ccb85d",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "positional argument follows keyword argument (4143973981.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [30]\u001b[1;36m\u001b[0m\n\u001b[1;33m    func_test(1,y=2,3)\u001b[0m\n\u001b[1;37m                     ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m positional argument follows keyword argument\n"
     ]
    }
   ],
   "source": [
    "func_test(1,y=2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "d174c70e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 关键字参数是不可以写在位置参数前面的"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "44bb5929",
   "metadata": {},
   "source": [
    "* 对于计算机而言：函数必须要有返回值（公理）\n",
    "* python:返回值给了一个默认值（None）\n",
    "> 1. 返回值的第一种情况：返回函数过程的计算结果\n",
    "> 2. 返回值的第二种情况：返回函数过程运算的过程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "bd481e9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func(x):\n",
    "    y = 2*x\n",
    "    return y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "cfbee692",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    }
   ],
   "source": [
    "print(func(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47c6729d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
